package org.moda.common;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * 二元组
 * @param <T1>
 * @param <T2>
 * @author yangxuan
 */
public record Tuple2<T1, T2>(T1 _1, T2 _2) {
    public static <T1, T2> Tuple2<T1, T2> of(T1 t1, T2 t2) {
        return new Tuple2<T1, T2>(t1, t2);
    }

    public <T3, T4> Tuple2<T3, T4> map(Function<T1, T3> f1, Function<T2, T4> f2) {
        return new Tuple2<T3, T4>(f1.apply(this._1), f2.apply(this._2));
    }

    public <T3> T3 fold(BiFunction<T1, T2, T3> f) {
        return f.apply(this._1, this._2);
    }
}
